<?php
namespace Home\Controller;

class VillaController extends HomeController {

    public function index(){
    	$banner = M("Ad")->where(array('id'=>9))->find();
        $this->assign('banner',$banner);  

	    $map['show'] = 1;
        $obj = M('Paper');
        $count = $obj->where($map)->count();
        import("Common.ORG.AmPage");
        $page = new \Page($count, 6);
        $show = $page->show();
        $list = $obj->where($map)->order('sort asc,id desc')->limit($page->firstRow . ',' . $page->listRows)->select();
        foreach ($list as $key => $value) {
        	$list[$key]['info'] = M('Info')->field('id,title,short')->where(array('paperID'=>$value['id']))->order('sort asc,id asc')->select();
        }
        $this->assign('list',$list);
        $this->assign('page',$show);

    	$this->display();
    }

    public function detail(){
        $banner = M("Ad")->where(array('id'=>9))->find();
        $this->assign('banner',$banner);  
        
        $id = I('get.id');
        if ($id=='' || !is_numeric($id)) {
            $this->error('参数错误');
        }

        $map['id'] = $id;
        $map['show'] = 1;     
        $list = M('Info')->where($map)->find();
        if (!$list) {
            $this->error('文章不存在');
        }else{
            M('Info')->where($map)->setInc('hit');

            $this->assign('list', $list);

            unset($map);
            $map['show'] = 1;
            $map['paperID'] = $list['paperID'];
            $map['id'] = array('gt',$list['id']);
            $next = M('Info')->field('id,title,short,createTime')->where($map)->order('id asc')->find();
            $this->assign('next',$next);

            $map['show'] = 1;
            $map['paperID'] = $list['paperID'];
            $map['id'] = array('lt',$list['id']);
            $up = M('Info')->field('id,title,short,createTime')->where($map)->order('id desc')->find();
            $this->assign('up',$up);

            //设计师
            $obj = M('Designer');
            unset($map);
            $map['show'] = 1;
            $designer = $obj->where($map)->order('rand()')->limit(2)->select();
            foreach ($designer as $key => $value) {
                unset($map);
                $map['disID'] = $value['id'];
                $map['cid'] = 2;
                $designer[$key]['count'] = M('Feedback')->where($map)->count()+20;
            }
            $this->assign('designer',$designer);

            //案例
            $obj = M('Case');
            unset($map);
            $map['show'] = 1;
            $case = $obj->where($map)->order('rand()')->limit(1)->select();
            $this->assign('case',$case);

            //楼盘
            $obj = M('Property');
            unset($map);
            $map['show'] = 1;
            $property = $obj->where($map)->order('rand()')->limit(2)->select();
            foreach ($property as $key => $value) {
                unset($map);
                $map['disID'] = $value['id'];
                $map['cid'] = array('in',array(3,4));
                $property[$key]['count'] = M('Feedback')->where($map)->count()+40;
            }
            $this->assign('property',$property);
            $this->display();
        }
    }
  
}